<?php

/**
 * sfDenariiPayment actions.
 *
 * @package    waa
 * @subpackage sfDenariiPayment
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2692 2006-11-15 21:03:55Z fabien $
 */
class sfDenariiPaymentActions extends sfActions
{
  /**
   * Executes index action
   *
   */
  public function executeIndex()
  {
    //$this->forward('default', 'module');
  }
  public function executeRequestPayment()
  {
    //$IPGURL = 'http://www.denariicards.com/ipgwebservice/default.asmx?WSDL';
    $soap = new SoapClient(sfConfig::get('mod_sfdenariipayment_gateway'));
    $date = $this->getRequestParameter('PAN_exp_date');
    $month = $date['month'];
    if(strlen($month) == 1)
      $month = '0'.$date['month'];
    $exp_date = substr($date['year'],2,4).$month;
    $arr = array(
    'nMerchantId' => 30005,
    'nTerminalId' => 1,
    'sPasscode' => '1234',
    'cardType' => $this->getRequestParameter('credit_card_type'),
    'sCardNo' => $this->getRequestParameter('PAN'),
    'sExpirationDate' => $exp_date,
    'sCCV2' => $this->getRequestParameter('CVV2'),
    'sEmail' => $this->getRequestParameter('email'),
    'sFirstName' => $this->getRequestParameter('first_name'),
    'sLastName' => $this->getRequestParameter('last_name'),
    'sAddress' => $this->getRequestParameter('AVS_address'),
    'sCity' => $this->getRequestParameter('city'),
    'sState' => $this->getRequestParameter('state'),
    'sZipCode' => $this->getRequestParameter('AVS_zip_code'),
    'sCountry' => $this->getRequestParameter('country'),
    'sPhone' => $this->getRequestParameter('phone'),
    'nAmount' => 10.0,
    'nPreviousReferenceTransactionId' => 0,
    'sPreviousAuthorizationId' => 0,
    'sVerificationReferenceId' => 0,
    'sPin' => ' ',
    'sText1' => 'We Are Amazon - Donation',
    'sText2' => 'www.weareamazon.org',
    );
    @$result = $soap->CreditCardSale($arr);
    $this->setFlash('result', $result);
    $this->redirect('sfDenariiPayment/response');
  }
  public function handleErrorRequestPayment()
  {
    $this->setTemplate('index');
    return sfView::SUCCESS;
  }
  public function executeResponse()
  {
    if($this->hasFlash('result'))
    {
      $this->status = "Error";
      $this->success = false;
      $this->result = $this->getFlash('result');
      if($this->result->CreditCardSaleResult->m_nResponseCode == 0 || $this->result->CreditCardSaleResult->m_bSuccess == true)
      {
        $this->status = "Exito";
        $this->success = true;
      }
      return sfView::SUCCESS;
    }
    $this->redirect('@homepage');
  }
}
